package mapstruct_test;

import mapstruct_test.converter.StudentConverter;
import model.Student;
import model.StudentVO;
import org.mapstruct.factory.Mappers;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhanghp
 * @date 2022-07-17 13:44
 */
public class Main {

	/**
	 * Mapstruct 映射
	 */
	private static final StudentConverter converter;

	/**
	 * Student
	 */
	private static final Student STUDENT;

	/**
	 * Student list
	 */
	private static final List<Student> LIST;

	static {
		converter = Mappers.getMapper(StudentConverter.class);

		// po数据准备
		STUDENT = new Student();
		STUDENT.setId(1);
		STUDENT.setName("张三");
		STUDENT.setPhoto("照片");

		// po list 数据准备
		LIST = new ArrayList<>();
		for (int i = 0; i < 5; i++) {
			Student student = new Student();
			student.setId(i);
			student.setName("张三 : " + i);
			student.setPhoto("照片 : " + i);
			LIST.add(student);
		}
	}

	public static void main(String[] args) {

		// Student -> StudentVO
		System.out.println(getVO());

		// List<Student> -> List<StudentVO>
		System.out.println(getVOList());
	}

	/**
	 * Student -> StudentVO
	 * @return StudentVO
	 */
	public static StudentVO getVO() {
		// 转换
		return converter.toVO(STUDENT);
	}

	/**
	 * List<Student> -> List<StudentVO>
	 * @return List<StudentVO>
	 */
	public static List<StudentVO> getVOList() {
		// 转换
		return converter.toVO(LIST);
	}

}
